﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Linq.Expressions;

using LeanEngine.Entity;
using LeanEngine.Collections;

namespace LeanEngine.Data.Linq
{
    /// <summary>
    /// Represents extensions methods for JOIN statements
    /// </summary>
    public static class JoinExtensions
    {
        /// <summary>
        /// Mark a many to many relation as a inner join
        /// </summary>
        public static TSource AsJoinRelation<TSource>(this ChangeTrackerCollection<TSource> source)
            where TSource : class
        {
            return default(TSource);
        }

        /// <summary>
        /// Mark a many to many relation as a left join
        /// </summary>
        public static TSource AsLeftJoinRelation<TSource>(this ChangeTrackerCollection<TSource> source)
            where TSource : class
        {
            return default(TSource);
        }

        /// <summary>
        /// Mark a many to many relation as a left join
        /// </summary>
        public static TSource AsRightJoinRelation<TSource>(this ChangeTrackerCollection<TSource> source)
            where TSource : class
        {
            return default(TSource);
        }

        /// <summary>
        /// Mark a join operation as a left join
        /// </summary>
        public static IQueryable<TSource> AsLeftJoin<TSource>(this IQueryable<TSource> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            return source.Provider.CreateQuery<TSource>(Expression.Call(null, ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(new Type[] { typeof(TSource) }), new Expression[] { source.Expression }));
        }

        /// <summary>
        /// Mark a join operation as a right join
        /// </summary>
        public static IQueryable<TSource> AsRightJoin<TSource>(this IQueryable<TSource> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            return source.Provider.CreateQuery<TSource>(Expression.Call(null, ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(new Type[] { typeof(TSource) }), new Expression[] { source.Expression }));
        }
    }
}
